package com.mt.api.constants.enums;

import com.mt.api.util.EnumMappingUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Map;
import java.util.Objects;

/**
 * @Author: plover
 * @Date: 2021/01/25/10:27
 * @Description: 尺码排序号枚举值
 */
@Getter
@AllArgsConstructor
public enum SizeSortNumEnum {
    XXXS(1, "XXXS"),
    THREE_XS(1, "3XS"),
    XXS(2, "XXS"),
    TWO_XS(2, "2XS"),
    XS(3, "XS"),
    S(4, "S"),
    M(5, "M"),
    L(6, "L"),
    XL(7, "XL"),
    XXL(8, "XXL"),
    TWO_XL(8, "2XL"),
    XXXL(9, "XXXL"),
    THREE_XL(9, "3XXL"),
    XXXXL(10, "XXXXL"),
    FOUR_XL(10, "4XL"),
    ;

    private Integer sortNum;
    private String name;

    private static final Map<String, SizeSortNumEnum> statusEnumMap =
            EnumMappingUtil.toMappingMap(SizeSortNumEnum.class, SizeSortNumEnum::getName);

    public static SizeSortNumEnum ofName(String name) {
        return statusEnumMap.get(name);
    }

    public static Integer sortNumOfName(String name) {
        name = name.toUpperCase();
        return Objects.nonNull(statusEnumMap.get(name)) ? statusEnumMap.get(name).getSortNum() : 0;
    }

}
